package com.xu.seal.utils;

import java.util.Random;

public class RandomStringUtils {

    public static String generateRandomAlphaNumeric(int length) {
        if (length < 1) {
            return "";
        }

        final String charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        Random random = new Random();
        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int randomIndex = random.nextInt(charSet.length());
            char randomChar = charSet.charAt(randomIndex);
            sb.append(randomChar);
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String randomString = generateRandomAlphaNumeric(10); // 生成一个长度为10的随机字符串
        System.out.println(randomString);
    }
}